from codex import * from time import sleep import math CENTER = 120 # Create a center line on the display display.fill (BLACK) display.draw_line(CENTER, 0, CENTER, 105, PINK) display.draw_line(CENTER, 95, CENTER, 239, PINK) display.draw_line(0, CENTER, 105, CENTER, PINK) display.draw_line(95, CENTER, 239, CENTER, PINK) x = CENTER while True: val = accel.read() # Get only the x value tilt_x = val[0] # Scale the value to +/- 1.0 scaled = (tilt_x / 16384) # Cap max and min value scaled = min(max(scaled, -1), 1) # Calculate degrees degrees = math.asin(scaled) * 180 / math.pi # Just an integer, please degrees = int(degrees) # Erase the old circle display.fill_rect(x, 105, 50, 30, BLACK) x = CENTER + degrees # Draw the box display.fill_rect(x, 105, 50, 30, BLUE) sleep(0.2)